import { defHttp } from '@/utils/http';
import {} from './types/index';
enum API {
  queryApplicationPageList = '/devops/application/list',
  addApplicationData = '/devops/application',
  handelApplicationData = '/devops/application',
  handelComponentData = '/devops/component',
  environmentListData = '/devops/environment/pageList',
  environmentData = '/devops/environment',
  spaceSelecttData = '/devops/space/list',
  AllenvironmentData = '/devops/environment/list',
  podListData = '/devops/pod/list',
  podLogData = '/devops/pod/log',
  componentPipeline = '/devops/pipeline/componentPipeline',
  operationFeature = '/devops/trait/list',
  deploymentUnit = '/devops/deploymentUnit/page',
}

// 应用-查询应用列表-携带组件信息
export const queryApplicationPageListFun = (data?: any) => defHttp.post({ url: API.queryApplicationPageList, data });

// 查询应用-组件列表（带权限）
export const queryAppPermList = (data?: any) =>
  defHttp.post({ url: '/devops/application/applicationListWithComponentPermissions', data });

// 应用-新增应用
export const addApplicationFun = (data?: any) => defHttp.post({ url: API.addApplicationData, data });

//应用-删除应用
export const deleteApplicationFun = (id: any) => defHttp.delete({ url: `${API.handelApplicationData}/${id}` });

//应用-编辑应用
export const putApplicationFun = (data: any) => defHttp.put({ url: API.handelApplicationData, data });

// 应用-新增组件
export const addComponentData = (data?: any) => defHttp.post({ url: API.handelComponentData, data });

//应用-删除组件
export const deleteComponentData = (id: any) => defHttp.delete({ url: `${API.handelComponentData}/${id}` });

//应用-编辑组件
export const putComponentData = (data: any) => defHttp.put({ url: API.handelComponentData, data });

//应用-查询应用详情
export const getAppData = (id: string | number) => defHttp.get({ url: `${API.handelApplicationData}/${id}` });

//应用-详情-环境管理列表
export const querEnvironmentPageListFun = (data?: any) => defHttp.post({ url: API.environmentListData, data });

//应用-详情-新增环境管理
export const addEnvironmentFun = (data?: any) => defHttp.post({ url: API.environmentData, data });

//应用-详情-交付空间查询
export const querSpaceFun = (data?: any) => defHttp.post({ url: API.spaceSelecttData, data });

//应用-详情-删除环境
export const deleteEnvironmentFun = (uuid: any) => defHttp.delete({ url: `${API.environmentData}/${uuid}` });

//应用-详情-编辑环境
export const putEnvironmentFun = (data: any) => defHttp.put({ url: API.environmentData, data });

//应用-查询组件详情
export const getAllComponentData = (id: any) => defHttp.get({ url: `/devops/component/label/${id}` });

//应用-详情-环境列表（全量）
export const getAllEnvironmentFun = (data: any) => defHttp.post({ url: API.AllenvironmentData, data });

//应用-详情-获取pod列表
export const getPodListDataFun = (data: Application.PodPipeline) => defHttp.post({ url: API.podListData, data });

//应用-详情-获取pod日志
export const getPodLogDataFun = (data: Application.PodPipeline) => defHttp.post({ url: API.podLogData, data });

//应用-详情-查询组件流水线信息
export const getComponentPipelineFun = (data: Application.ComponentPipeline) =>
  defHttp.post({ url: API.componentPipeline, data });

//应用-详情-查询运维特征列表(有过滤条件，可以分页)
export const getOperationFeatureFun = (data: any) => defHttp.post({ url: API.operationFeature, data });

//应用-详情-根据流水线编码分页获取部署单
export const getDeploymentUnitFun = (data: any) => defHttp.post({ url: API.deploymentUnit, data });

//查询字典列表(有过滤条件)
export const getDictionaryTableList = (data?: any) => defHttp.post({ url: '/devops/dict/list', data });

//获取部署任务的部署策略
export const getDeployStrategyList = (data?: any) => defHttp.post({ url: '/devops/task/deploy/strategy/dict', data });

// 通过流水线实例编码查询部署单详情
export const queryByPipelineInstanceCode = (code: string) =>
  defHttp.get({ url: `/devops/deploymentUnit/queryByPipelineInstanceCode?pipelineInstanceCode=${code}` });

// 获取组件变更分页列表
export const getChangeMgmtList = (data?: any) => defHttp.post({ url: '/devops/changeMgmt/page', data });

// 新增变更
export const addChangeMgmtList = (data: Application.addChangeMgmtParams) =>
  defHttp.post({ url: '/devops/changeMgmt/add', data });

// 更新现有变更
export const updateChangeMgmtList = (data: Application.addChangeMgmtParams) =>
  defHttp.post({ url: '/devops/changeMgmt/update', data });

// 根据变更id获取变更详情
export const queryChangeMgmtList = (id: string | number) => defHttp.get({ url: `/devops/changeMgmt/${id}` });

// 根据id删除变更
export const deleteChangeMgmtList = (id: string | number) => defHttp.delete({ url: `/devops/changeMgmt/${id}` });

// 部署单继续
export const deploymentUnitContinue = (id: string | number) =>
  defHttp.get({ url: `/devops/deploymentUnit/continue/${id}` });

// 部署单回滚
export const deploymentUnitRollback = (id: string | number) =>
  defHttp.get({ url: `/devops/deploymentUnit/rollback/${id}` });

// 该环境是否存在关联流水线
export const checkIsEnvironmentPipeline = (id: string | number) =>
  defHttp.get({ url: `/devops/environment/existsPipeline/${id}` });
